//
//  JoInfoView.m
//  RunningMan
//
//  Created by 姜勇利 on 16/5/19.
//  Copyright © 2016年 JohnnyB. All rights reserved.
//

#import "JoInfoView.h"
#import "Masonry.h"
#import <CoreLocation/CoreLocation.h>
#import "APPTools.h"


#define VIEW_WIDTH self.frame.size.width
#define VIEW_HEIGHT self.frame.size.height

@interface JoInfoView ()

@end

@implementation JoInfoView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubViews];
    }
    return self;
}


- (void)creatSubViews
{
// 用户名
    self.nameLabel = [[UILabel alloc]init];
    [self addSubview:self.nameLabel];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.textAlignment = YES;
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self).with.offset(0);
        make.width.mas_equalTo(VIEW_WIDTH / 2.f);
        make.height.mas_equalTo(VIEW_HEIGHT / 4.f);
    }];
    self.nameLabel.font = [UIFont systemFontOfSize:50 weight:0.001];
    [self.nameLabel sizeToFit];
    self.nameLabel.adjustsFontSizeToFitWidth = YES;
    
// 装饰圆圈
    UIImageView *circleImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"9"]];
    [self addSubview:circleImage];
    [circleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.nameLabel.mas_centerY);
        make.width.mas_equalTo(VIEW_WIDTH / 18.f);
        make.height.mas_equalTo(VIEW_WIDTH / 18.f);
        make.left.equalTo(self.nameLabel.mas_right).with.offset(VIEW_WIDTH / 18.f);
    }];
// 分割线
    UIView *lineView = [[UIView alloc]init];
    [self addSubview:lineView];
    lineView.backgroundColor = [UIColor grayColor];
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(VIEW_HEIGHT / 5.f);
        make.width.mas_equalTo(0.8);
        make.left.equalTo(circleImage.mas_right).with.offset(VIEW_WIDTH / 18.f);
        make.top.equalTo(self).with.offset(VIEW_HEIGHT / 24.f);
    }];
// 用户头像
    self.userImage = [[UIImageView alloc]init];
    [self addSubview:self.userImage];
    self.userImage.clipsToBounds = YES;
    [self.userImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(VIEW_WIDTH / 4.5f);
        make.centerY.mas_equalTo(self.nameLabel.mas_centerY);
        make.right.equalTo(self.mas_right).with.offset(-VIEW_WIDTH / 16.f);
    }];
    self.userImage.layer.cornerRadius = VIEW_WIDTH / 9.f;
// 彩色分割线
    UIView *lineViewColor = [[UIView alloc]init];
    [self addSubview:lineViewColor];
    lineViewColor.backgroundColor = [UIColor colorWithRed:0.01 green:0.66 blue:0.62 alpha:1.0];
//    lineViewColor.backgroundColor = [UIColor greenColor];
    [lineViewColor mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(3);
        make.width.mas_equalTo(VIEW_WIDTH * 3 / 5.f);
        make.left.equalTo(self).with.offset(0);
        make.top.equalTo(self.nameLabel.mas_bottom).with.offset(0);
    }];
// 毛玻璃
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    UIVisualEffectView *visualEffectView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
    visualEffectView.alpha = 0.9;
    [self addSubview:visualEffectView];
    [visualEffectView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(lineViewColor.mas_bottom).with.offset(0);
        make.left.equalTo(self).with.offset(0);
        make.width.mas_equalTo(VIEW_WIDTH);
        make.height.mas_equalTo(VIEW_HEIGHT / 2.f);
    }];
    
// 城市定位
    UIImageView *locationIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"10"]];
    [visualEffectView addSubview:locationIcon];
    [locationIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(visualEffectView).with.offset(VIEW_WIDTH / 10.f);
        make.top.equalTo(visualEffectView).with.offset(VIEW_WIDTH / 20.f);
        make.width.height.mas_equalTo(VIEW_WIDTH / 20.f);
    }];

    self.cityLabel = [[UILabel alloc]init];
    [visualEffectView addSubview:self.cityLabel];
    self.cityLabel.textColor = [UIColor whiteColor];
//    self.cityLabel.textAlignment = YES;
    self.cityLabel.adjustsFontSizeToFitWidth = YES;
    [self.cityLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(locationIcon.mas_right).with.offset(VIEW_WIDTH / 30.f);
        make.centerY.mas_equalTo(locationIcon.mas_centerY);
        make.height.mas_equalTo(locationIcon.frame.size.height);
        make.width.mas_equalTo(VIEW_WIDTH / 3.f);
    }];
    
// 天气
    self.imageWeather = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"T99"]];
    [visualEffectView addSubview:self.imageWeather];
    [self.imageWeather mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.userImage.mas_centerX);
        make.top.equalTo(visualEffectView).with.offset(VIEW_WIDTH / 20.f);
        make.width.height.mas_equalTo(VIEW_WIDTH * 1 / 5.f);
    }];
    
    self.weaLabel = [[UILabel alloc]init];
    [visualEffectView addSubview:_weaLabel];
    [_weaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.cityLabel.mas_left).with.offset(0);
        make.top.equalTo(self.cityLabel.mas_bottom).with.offset(0);
        make.height.mas_equalTo(VIEW_WIDTH / 8.f);
        make.right.equalTo(_imageWeather.mas_left).with.offset(-VIEW_WIDTH / 16.f);
    }];
    _weaLabel.numberOfLines = 0;
    _weaLabel.textColor = [UIColor lightTextColor];
    self.weaLabel.adjustsFontSizeToFitWidth = YES;
    
    UIImageView *weaIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"18"]];
    [visualEffectView addSubview:weaIcon];
    [weaIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(VIEW_WIDTH / 20.f);
        make.centerX.mas_equalTo(locationIcon.mas_centerX);
        make.centerY.mas_equalTo(_weaLabel.mas_centerY);
    }];
    
// 适宜跑步
    UILabel *runLabel = [[UILabel alloc]init];
    [visualEffectView addSubview:runLabel];
    [runLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_weaLabel.mas_left).with.offset(0);
        make.top.equalTo(_weaLabel.mas_bottom).with.offset(10);
        make.bottom.equalTo(visualEffectView.mas_bottom).with.offset(-10);
        make.right.equalTo(visualEffectView.mas_right).with.offset(-VIEW_WIDTH / 16.f);
    }];
    runLabel.numberOfLines = 0;
    runLabel.text = @"The weather is not fine and suitable for running";
    runLabel.textColor = [UIColor lightTextColor];
    runLabel.adjustsFontSizeToFitWidth = YES;
    
    UIImageView *runIcon = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"17"]];
    [visualEffectView addSubview:runIcon];
    [runIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(locationIcon.mas_centerX);
        make.centerY.mas_equalTo(runLabel.mas_centerY);
        make.width.height.mas_equalTo(VIEW_WIDTH / 20.f);
    }];
    
// 用户个人信息
    UIButton *userButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:userButton];
    userButton.backgroundColor = [UIColor colorWithRed:0.54 green:0.17 blue:0.88 alpha:1.0];
    [userButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(visualEffectView.mas_bottom).with.offset(0);
        make.left.equalTo(self).with.offset(0);
        make.width.mas_equalTo(VIEW_WIDTH / 4.f);
        make.height.mas_equalTo(VIEW_HEIGHT / 4.f - 3);
    }];
    [userButton setImage:[UIImage imageNamed:@"12"] forState:UIControlStateNormal];
    [userButton addTarget:self action:@selector(handlePush:) forControlEvents:UIControlEventTouchUpInside];
    userButton.tag = 100;
    
// 照片
    UIButton *photoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:photoButton];
    photoButton.backgroundColor = [UIColor colorWithRed:0.63 green:0.40 blue:0.82 alpha:1.0];
    [photoButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(visualEffectView.mas_bottom).with.offset(0);
        make.left.equalTo(userButton.mas_right).with.offset(0);
        make.width.mas_equalTo(VIEW_WIDTH / 4.f);
        make.height.mas_equalTo(VIEW_HEIGHT / 4.f - 3);
    }];
    [photoButton setImage:[UIImage imageNamed:@"13"] forState:UIControlStateNormal];
    [photoButton addTarget:self action:@selector(handlePush:) forControlEvents:UIControlEventTouchUpInside];
    photoButton.tag = 200;
    
// 视频收藏
    UIButton *collectionButton = [UIButton buttonWithType:UIButtonTypeCustom];
    collectionButton.backgroundColor = [UIColor colorWithRed:0.85 green:0.44 blue:0.84 alpha:1.0];
    [self addSubview:collectionButton];
    [collectionButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(visualEffectView.mas_bottom).with.offset(0);
        make.left.equalTo(photoButton.mas_right).with.offset(0);
        make.width.mas_equalTo(VIEW_WIDTH / 4.f);
        make.height.mas_equalTo(VIEW_HEIGHT / 4.f - 3);
    }];
    [collectionButton setImage:[UIImage imageNamed:@"14"] forState:UIControlStateNormal];
    [collectionButton addTarget:self action:@selector(handlePush:) forControlEvents:UIControlEventTouchUpInside];
    collectionButton.tag = 300;
    
// 统计
    UIButton *statisticsButton = [UIButton buttonWithType:UIButtonTypeCustom];
    statisticsButton.backgroundColor = [UIColor colorWithRed:0.89 green:0.81 blue:0.34 alpha:1.0];
    [self addSubview:statisticsButton];
    [statisticsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(visualEffectView.mas_bottom).with.offset(0);
        make.left.equalTo(collectionButton.mas_right).with.offset(0);
        make.right.equalTo(self).with.offset(0);
        make.bottom.equalTo(self.mas_bottom).with.offset(0);
    }];
    [statisticsButton setImage:[UIImage imageNamed:@"15"] forState:UIControlStateNormal];
    [statisticsButton addTarget:self action:@selector(handlePush:) forControlEvents:UIControlEventTouchUpInside];
    statisticsButton.tag = 400;
    
    
}



#pragma mark - button点击事件
- (void)handlePush:(UIButton *)button
{
    self.pushNextPage(button);
}




/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
